package org.huntaway.ant.tools;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AntExample {
	private final static Logger logger = LoggerFactory
			.getLogger(AntExample.class);

	public static void main(String[] args) {
		String str = "111.3.22.11";
		str = str.replaceAll("(^|\\.)(\\d)(\\.|$)", "$100$2$3");
		System.out.println(str);
		str = str.replaceAll("(^|\\.)(\\d{2})(\\.|$)", "$10$2$3");
		System.out.println(str);
		str = str.replaceAll("(^|\\.)(\\d{2})(\\.|$)", "$10$2$3");
		System.out.println(str);
		str = str.replaceAll("(^|\\.)(\\d{1})(\\.|$)", "$100$2$3");

		System.out.println(str);

		System.out.println("Hello World!");
		String str1 = "asdfghjkl";
		String str2 = "a$khsd$kahdkada";
		String str3 = "/akhsdkahdkada";
		String str4 = "\\akhsdkahdkada";
		String str5 = "%akhsdkahdkada";
		String str6 = "#akhsdkahdkada";
		System.out.println(str2 = str2.replaceAll("\\$", ""));
		System.out.println(str1.replaceAll("asd", str2));
		System.out.println(str1.replaceAll("asd", str3));
		System.out.println(str1.replaceAll("asd", str4));
		System.out.println(str1.replaceAll("asd", str5));
		System.out.println(str1.replaceAll("asd", str6));
		AntUtil antUtil = new AntUtil();
		/*
		 * antUtil.tar(); antUtil.zip();
		 */
		AntExample ae = new AntExample();
		ae.runBat();
		File newFile = new File(
				"D:/tools/Java/apache-tomcat-6.0.35/bin/startup.bat");
		logger.info(newFile.getName());
	}

	private void runBat() {
		File newFile = new File("E:/jskyme/mcear.bat");
		logger.info(newFile.getPath());
		open(newFile.getPath());
	}

	public void copyTest(File srcFile, File distFile) {
		AntUtil.fileCopy(null, null);
	}

	public void getTest(File srcFile, File distFile) {
		try {
			AntUtil.get(
					new URL("http://www.foxmail.com.cn/doanload/fm50ch.exe"),
					new File("d:\\fm50ch.exe"));
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void open(String str) {
		String[] cmd = new String[5];
		cmd[0] = "cmd";
		cmd[1] = "/c";
		cmd[2] = "start";
		cmd[3] = " ";
		cmd[4] = str;
		exec(cmd);
	}

	private void exec(String[] cmd) {
		try {
			Runtime.getRuntime().exec(cmd);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
